package com.ucs.restlet.firstres;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Restlet;
import org.restlet.data.Protocol;
import org.restlet.routing.Router;
import org.restlet.routing.VirtualHost;
import org.restlet.util.ServerList;

public class FirstResourceApplication extends Application{
	/** The list of items is persisted in memory. */  
    private final ConcurrentMap<String, Item> items = new ConcurrentHashMap<String, Item>();
	@Override
	public Restlet createInboundRoot() {
		Router router = new Router(getContext());
		
		// Defines a route for the resource "list of items" 
		router.attach("/users", ItemsResource.class);
		// Defines a route for the resource "item"   
        router.attach("/items/{itemName}", ItemResource.class);   
  
        return router;   

	}
	/**  
     * Returns the list of registered items.  
     *   
     * @return the list of registered items.  
     */  
    public ConcurrentMap<String, Item> getItems() {   
        return items;   
    }   

	public static void main(String[] args) {
		Component component = new Component();
		ServerList serverList = component.getServers();
		serverList.add(Protocol.HTTP, 8182);
		VirtualHost virtualHost = component.getDefaultHost();
		virtualHost.attach(new FirstResourceApplication());
		try {
			component.start();			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
